import React, {useState} from 'react';
import {RouteItem} from "../../Pages/type";
import {Menu} from "antd";
import style from "./menu-component.module.css";
import {getConfig2Menu} from "./menuIterCache";
import {NotFountRoute, selectRoutes} from "./contentIter";

export interface MenuNavProps {
  mode?:'horizontal'| 'vertical';
  setKey?:(d:string)=>void;
  routes:RouteItem[];
  authInfo?:string[];
  defaultKey:string;
}
export  function getContent ( key:string, routes:RouteItem[]=[]){
  return   selectRoutes(key, routes) || NotFountRoute;
}

export default ({routes=[],authInfo=[], setKey=(s:string)=>{},mode='horizontal',defaultKey}:MenuNavProps)=>{
  return (
    <Menu mode={mode}
          className={style.topMenu}
          onClick={({item,key})=>setKey(key as string)}  defaultSelectedKeys={[defaultKey]}>
      {getConfig2Menu(routes,authInfo)}
    </Menu>
    )
}


